import { computed, reactive, ref, toRefs } from "vue";

import useUserStore from '@/store/modules/user'
const userStore = useUserStore()
const userInfo = ref({
    userId: null,
    userName: null,
    userType: null,
    email: null,
    phoneNumber: null,
    status: 0,
    createTime: null,
    updateTime: null,
    remark: null,
    avatarUrl: null,
    roleIds: [],
    roles: []
})
const permissions = ref([])



const accountList = ref<Array<{
    accountId: number,
    name: string,
    code: string,
    type: string,
    status: number,
    createTime: Date | null,
    updateTime: Date | null,
    remark: string | null
}>>([]);
const productList = ref<Array<{
    productId: number,
    productName: string,
    productCode: string,
    type: string,
    status: number,
    createTime: Date | null,
    updateTime: Date | null,
    remark: string | null
}>>([]);

const transactions_fundList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const autoCalcAmount = ref(true);
const dividendType = ref(null);
const soldOffSelected = ref([])


const data = reactive({
    form: {
        transactionId: null,
        userId: null,
        type: null,
        accountId: null,
        productId: null,
        submitTime: null,
        confirmDate: null,
        price: 0,
        quantity: 0,
        amount: 0,
        fee: 0,
        priceDate: null,
        transWith: null,
        comment: null
    },
    queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        accountId: null,
        productId: null,
        submitTime: null,
        confirmDate: null,
        type: null,
        price: null,
        quantity: null,
        amount: null,
        fee: null,
        priceDate: null,
        transWith: null,
        comment: null
    },
    rules: {
    }
});

const { queryParams, form, rules } = toRefs(data);
const isCash = computed(() => dividendType.value === 'cash' && form.value.type === 'DIVIDEND')
const isDividend = computed(() => form.value.type === 'DIVIDEND')
const quantityShow = computed(() => (!isDividend.value) || !isCash.value)
const amountShow = computed(() => (!isDividend.value) || isCash.value)



export {
    accountList,
    productList,
    data,
    transactions_fundList,
    open,
    loading,
    showSearch,
    ids,
    single,
    multiple,
    total,
    title,
    autoCalcAmount,
    dividendType,
    soldOffSelected,
    userStore,
    userInfo,
    permissions,
    queryParams,
    form,
    rules,
    isCash,
    isDividend,
    quantityShow,
    amountShow,
}
